package org.dev.hi.hiui.banner.core;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.dev.hi.library.util.HiDisPlayUtils;


public
/**
 * Author WenPing 
 * CreateTime 2021/4/18.
 * Description:
 */

class HiNumIndicator extends FrameLayout implements HiIndicator<FrameLayout> {

    private static final int VWC = ViewGroup.LayoutParams.WRAP_CONTENT;

    private int mPointLeftRightPadding;
    private int mPointTopBottomPadding;

    public HiNumIndicator(@NonNull Context context) {
        this(context, null);
    }

    public HiNumIndicator(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HiNumIndicator(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPointLeftRightPadding = HiDisPlayUtils.dp2px(10);
        mPointTopBottomPadding = HiDisPlayUtils.dp2px(10);
    }

    @Override
    public FrameLayout get() {
        return this;
    }

    @Override
    public void onInflate(int count) {
        removeAllViews();
        if (count <= 0) {
            return;
        }
        LinearLayout groupView = new LinearLayout(getContext());
        groupView.setOrientation(LinearLayout.HORIZONTAL);
        groupView.setPadding(0, 0, mPointLeftRightPadding, mPointTopBottomPadding);

        TextView indexTv = new TextView(getContext());
        indexTv.setText("1");
        indexTv.setTextColor(Color.WHITE);
        groupView.addView(indexTv);

        TextView symbolTv = new TextView(getContext());
        symbolTv.setText(" / ");
        symbolTv.setTextColor(Color.WHITE);
        groupView.addView(symbolTv);

        TextView countTv = new TextView(getContext());
        countTv.setText(String.valueOf(count));
        countTv.setTextColor(Color.WHITE);
        groupView.addView(countTv);
        //线性布局到帧布局中，使用过的尺寸参数是帧布局的
        LayoutParams groupViewParams = new LayoutParams(VWC, VWC);
        groupViewParams.gravity = Gravity.END | Gravity.BOTTOM;
        addView(groupView, groupViewParams);
    }


    @Override
    public void onPointChange(int current, int count) {
        ViewGroup viewGroup = (ViewGroup) getChildAt(0);
        TextView indexTv = (TextView) viewGroup.getChildAt(0);
        TextView countTv = (TextView) viewGroup.getChildAt(2);
        indexTv.setText(String.valueOf(current + 1));
        countTv.setText(String.valueOf(count));
    }
}
